package hu.myai.test.util;

import hu.myai.api.indicators.IndicatorInterface;
import hu.myai.api.tick.AbstractTickProvider;
import hu.myai.api.tick.TickConsumerInterface;
import hu.myai.model.TickVO;
import hu.myai.util.pool.IndicatorPool;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

/**
 * @author bozbalint
 *
 */
public class IndicatorUtil {

	/**
	 * if someone create a indicator the dependencies goes to pool. This method
	 * feed all pooled indicator with ticks.
	 * */
	public static synchronized void feedAllPooledIndicator(String tickName) {
		List<IndicatorInterface> indicatorList = IndicatorPool.getIndicatorList(tickName);

		int i = 0;
		for (TickVO tick : generateTickList()) {
			tick.setTimestamp(i++);
			for (IndicatorInterface indicator : indicatorList) {
				indicator.addTick(tick);
			}
		}
	}

	public static synchronized void feedAllTickConsumer(AbstractTickProvider tickProvider) {

		int i = 0;
		for (TickVO tick : generateTickList()) {
			tick.setTimestamp(i++);
			for (TickConsumerInterface tickConsumer : tickProvider.getTickConsumerList()) {
				tickConsumer.addTick(tick);
			}
		}
	}

	public static synchronized List<TickVO> generateTickList() {
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");

		List<TickVO> retList = new ArrayList<TickVO>();

		try {
			int i =0;
			retList.add(new TickVO(121.0, 103.13, 22.129, 46.1250, 5000, formatter.parse("2009-01-01"), i++));
			retList.add(new TickVO(120.0, 104.00, 24.000, 47.1250, 5000, formatter.parse("2009-01-02"), i++));
			retList.add(new TickVO(120.0, 103.06, 23.060, 46.4375, 5000, formatter.parse("2009-01-03"), i++));
			retList.add(new TickVO(124.0, 102.75, 22.750, 46.9375, 5000, formatter.parse("2009-01-04"), i++));
			retList.add(new TickVO(130.0, 108.00, 23.000, 44.9375, 5000, formatter.parse("2009-01-05"), i++));
			retList.add(new TickVO(126.0, 107.56, 22.560, 44.2500, 5000, formatter.parse("2009-01-06"), i++));
			retList.add(new TickVO(122.0, 105.25, 22.250, 44.6250, 5000, formatter.parse("2009-01-07"), i++));
			retList.add(new TickVO(121.0, 107.49, 22.689, 45.7500, 5000, formatter.parse("2009-01-08"), i++));
			retList.add(new TickVO(120.0, 106.63, 23.629, 47.8125, 5000, formatter.parse("2009-01-09"), i++));
			retList.add(new TickVO(126.0, 107.00, 22.000, 47.5625, 5000, formatter.parse("2009-01-10"), i++));
			retList.add(new TickVO(130.0, 109.00, 24.000, 47.0000, 5000, formatter.parse("2009-01-11"), i++));
			retList.add(new TickVO(127.0, 110.00, 25.000, 44.5625, 5000, formatter.parse("2009-01-12"), i++));
			retList.add(new TickVO(118.0, 112.75, 27.750, 46.3125, 5000, formatter.parse("2009-01-13"), i++));
			retList.add(new TickVO(121.0, 113.50, 28.500, 47.6875, 5000, formatter.parse("2009-01-14"), i++));
			retList.add(new TickVO(120.0, 114.25, 29.250, 46.6875, 5000, formatter.parse("2009-01-15"), i++));
			retList.add(new TickVO(126.0, 115.25, 30.250, 45.6875, 5000, formatter.parse("2009-01-16"), i++));
			retList.add(new TickVO(130.0, 121.50, 36.500, 43.0625, 5000, formatter.parse("2009-01-17"), i++));
			retList.add(new TickVO(127.0, 126.88, 41.879, 43.5625, 5000, formatter.parse("2009-01-18"), i++));
			retList.add(new TickVO(118.0, 122.50, 37.500, 44.8750, 5000, formatter.parse("2009-01-19"), i++));
			retList.add(new TickVO(130.0, 119.00, 34.000, 43.0625, 5000, formatter.parse("2009-01-20"), i++));
			retList.add(new TickVO(127.0, 122.50, 37.500, 43.5625, 5000, formatter.parse("2009-01-21"), i++));
			retList.add(new TickVO(118.0, 118.00, 33.000, 44.8750, 5000, formatter.parse("2009-01-22"), i++));

			retList.add(new TickVO(119.0, 119.00, 25.200, 43.2450, 5000, formatter.parse("2009-01-23"), i++));
			retList.add(new TickVO(122.0, 122.00, 20.500, 43.1750, 5000, formatter.parse("2009-01-24"), i++));
			retList.add(new TickVO(118.0, 118.00, 22.400, 42.2150, 5000, formatter.parse("2009-01-25"), i++));
			retList.add(new TickVO(117.0, 117.00, 28.730, 42.8750, 5000, formatter.parse("2009-01-26"), i++));
			retList.add(new TickVO(118.0, 118.00, 31.000, 43.2850, 5000, formatter.parse("2009-01-27"), i++));
			retList.add(new TickVO(121.0, 121.00, 35.100, 43.8760, 5000, formatter.parse("2009-01-28"), i++));
			retList.add(new TickVO(122.0, 122.00, 35.600, 43.9760, 5000, formatter.parse("2009-01-28"), i++));

		} catch (ParseException e) {
			e.printStackTrace();
		}

		return retList;
	}

}
